import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gzmall_app/common/api.dart';
import 'package:gzmall_app/common/error_widget.dart';
import 'package:gzmall_app/common/setting_util.dart';
import 'package:gzmall_app/mine/account_safe.dart';
import 'package:gzmall_app/store/near_store_list_page.dart';
import 'package:oktoast/oktoast.dart';
import 'login/login.dart';
import 'home_page.dart';
import 'common/color_common.dart';
import 'mine/person_info_page.dart';
import 'mine/setting_page.dart';
import 'mine/message_center_page.dart';
import 'mine/coupon.page.dart';
import 'mine/order_page.dart';
import 'login/register.dart';
import 'mine/input_content.dart';
import 'login/reset_password.dart';
import 'mine/address_manage.dart';
import 'mine/address_add.dart';
import 'mine/select_regions.dart';
import 'mine/reset_phone.dart';
import 'mine/about.dart';
import 'mine/order_details.dart';
import 'mine/logistics.dart';
import 'goods/goods_details_page.dart';
import 'shoppping_cart/confirm_order.dart';
import 'package:gzmall_app/store/store_detail_page.dart';
import 'goods/search_goods_page.dart';
import 'mine/feedback_page.dart';
import 'mine/collect_page.dart';
import 'mine/footprint_page.dart';
import 'mine/follow_page.dart';
import 'package:amap_location/amap_location.dart';
import 'mine/open_store_page.dart';
import 'mine/coupon_center_page.dart';
import 'mine/order_comment_page.dart';
import 'topup/topup_page.dart';
import 'topup/topup_record_page.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  AMapLocationClient.setApiKey(Api.amapiOSId);
  setCustomErrorPage();

  runApp(new MyApp());
}

void setCustomErrorPage() {
  ErrorWidget.builder = (FlutterErrorDetails flutterErrorDetails) {
    print(flutterErrorDetails.toString());
    return FErrorWidget();
  };
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
    return OKToast(
        child: MaterialApp(
      title: SettingUtil.appName,
      theme: new ThemeData(
        primarySwatch: Colors.red,
        brightness: Brightness.light,
        primaryColor: ColorCommon.primaryColor,
        accentColor: ColorCommon.primaryColor,
        unselectedWidgetColor: Colors.grey,
        scaffoldBackgroundColor: ColorCommon.grey10,
      ),
      home: new HomePage(),
      routes: <String, WidgetBuilder>{
        '/login_page': (BuildContext context) => new LoginPage(),
        '/register_page': (BuildContext context) => new RegisterPage(),
        '/person_info_page': (BuildContext context) => new PersonInfoPage(),
        '/setting_page': (BuildContext context) => new SettingPage(),
        '/message_center_page': (BuildContext context) =>
            new MessageCenterPage(),
        '/coupon_page': (BuildContext context) => new CouponPage(),
        '/order_page': (BuildContext context) => new OrderPage(),
        '/input_content': (BuildContext context) => new InputContentPage(""),
        '/reset_password': (BuildContext context) => new ResetPasswordPage(),
        '/address_manage': (BuildContext context) =>
            new AddressManagePage(false),
        '/address_add': (BuildContext context) => new AddressAddPage(),
        '/select_regions': (BuildContext context) => new SelectRegionsPage(),
        '/account_safe': (BuildContext context) => new AccountSafePage(),
        '/reset_phone': (BuildContext context) => new ResetPhonePage(),
        '/about': (BuildContext context) => new AboutPage(),
        '/goods_details': (BuildContext context) => new GoodsDetailsPage(),
        '/confirm_order_page': (BuildContext context) => new ConfirmOrderPage(),
        '/near_store_list_page': (BuildContext context) =>
            new NearStoreListPage(),
        '/store_detail_page': (BuildContext context) => new StoreDetailPage(),
        '/search_goods_page': (BuildContext context) => new SearchGoodsPage(),
        '/feedback_page': (BuildContext context) => new FeedbackPage(),
        '/collect_page': (BuildContext context) => new CollectPage(),
        '/footprint_page': (BuildContext context) => new FootPrintPage(),
        '/follow_page': (BuildContext context) => new FollowPage(),
        '/open_store_page': (BuildContext context) => new OpenStorePage(),
        '/coupon_center_page': (BuildContext context) => new CouponCenterPage(),
        '/topup_page': (BuildContext context) => new TopupPage(),
        '/topup_record_page': (BuildContext context) => new TopupRecordPage(),
      },
    ));
  }
}
